/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 - 2008 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.taglib.head.js;

import com.genia.toolbox.basics.process.Comparators;

/**
 * class representing a javascript file to import.
 */
public final class JsScript
    implements Comparable<JsScript>
{
  /**
   * whether the link is cachable.
   */
  private final transient boolean cache;

  /**
   * the priority of the script link.
   */
  private final transient int priority;

  /**
   * the src link.
   */
  private final transient String src;

  /**
   * spring name where to get the UrlManager.
   */
  private final transient String urlManagerName;



  /**
   * constructor.
   * 
   * @param src
   *          the src link
   * @param urlManagerName
   *          spring name where to get the UrlManager
   * @param cache
   *          whether the link is cachable
   * @param priority
   *          the priority of the script link
   */
  public JsScript(final String src, final String urlManagerName, boolean cache, int priority)
  {
    this.src = src;
    this.urlManagerName = urlManagerName;
    this.cache = cache;
    this.priority = priority;
  }



  /**
   * Compares this object with the specified object for order. Returns a
   * negative integer, zero, or a positive integer as this object is less than,
   * equal to, or greater than the specified object.
   * <p>
   * 
   * @param other
   *          the Object to be compared
   * @return a negative integer, zero, or a positive integer as this object is
   *         less than, equal to, or greater than the specified object
   * @see java.lang.Comparable#compareTo(java.lang.Object)
   */
  public int compareTo(JsScript other)
  {
    return Comparators.NATURAL_ARRAY_COMPARATOR.compare(new Comparable[] { getPriority(), getSrc(), isCache(), getUrlManagerName() }, new Comparable[] { other.getPriority(), other.getSrc(),
        other.isCache(), other.getUrlManagerName() });
  }



  /**
   * getter for the priority property.
   * 
   * @return the priority
   */
  public int getPriority()
  {
    return priority;
  }



  /**
   * getter for the src property.
   * 
   * @return the src
   */
  public String getSrc()
  {
    return src;
  }



  /**
   * getter for the urlManagerName property.
   * 
   * @return the urlManagerName
   */
  public String getUrlManagerName()
  {
    return urlManagerName;
  }



  /**
   * getter for the cache property.
   * 
   * @return the cache
   */
  public boolean isCache()
  {
    return cache;
  }
}
